class AgendasController < ApplicationController
  
  def index
    @active_section = Section.find_by_short_name("Agendas");
    @subsections = @active_section.subsections
    @active_subsection_id = @subsections.first != nil ? @subsections.first.id : nil
    @categories = Hash.new    
    @subsections.each do |section|
        section_categories = Category.joins("right join accounts_categories on categories.id = accounts_categories.category_id").where("section_id = ? and account_id = ?",section.id,@current_account.id).order(:section_order).order(:category_order)
        
        info = Hash.new

        info[:categories] = section_categories

        section_categories.each do |category|
          if category.category_type == 'standard'
            @active_category_id = category.id
            break
          end
        end
        info[:active_category] = @active_category_id
        info[:has_active_categories] = section_categories.count > 0
        @categories[section.short_name] = info
    end

  end
  
  def calendar
    @active_section = Section.find_by_short_name("Calendario");
  end
  
end
